﻿@model Sheng.WeixinConstruction.Client.Shell.Models.LuckyTicketDrawResultViewModel

@{
    ViewBag.SubTitle = "活动";
    Layout = "~/Views/Shared/_LayoutBlank.cshtml";
}

<style type="text/css">
    body {
        margin-bottom: 0.55rem;
    }

    .campaignName {
        font-size: 0.14rem;
        font-weight: bold;
    }

    .campaignDescription {
        font-size: 0.13rem;
        color: #666;
    }

    #divMemberInfo {
        font-size: 0.14rem;
        line-height: 0.14rem;
        text-align: center;
        margin-top: 0.05rem;
    }

  
    #divShareMask {
        position: absolute;
        top: 0px;
        bottom: 0px;
        left: 0px;
        right: 0px;
        width: 100%;
        height: 100%;
        background-color: black;
        text-align: right;
        filter: alpha(opacity=80);
        -moz-opacity: 0.8;
        -khtml-opacity: 0.8;
        opacity: 0.8;
    }

    .divLuckyTicketItem {
        text-align: center;
        font-size: 0.2rem;
        color: #FF7F00;
        background-image: url(/Content/Images/bg_star.jpg);
        background-repeat: repeat;
        padding-top: 0.05rem;
        padding-bottom: 0.05rem;
        margin-bottom: 0.05rem;
    }

     #divFooter {
            position: fixed;
            bottom: 0px;
            left: 0px;
            right: 0px;
            height: 0.4rem;
            font-size: 0.14rem;
            text-align: center;
            background-color: #F5F5F5;
        }
</style>

<script>

    var _currentPage = 1;
    var _totalPage = 1;
    var _status = @((int)Model.CampaignBundle.Campaign.Status);
    var _campaignId = getQueryString("campaignId");

    $(document).ready(function () {

        var jsApiConfigStr = "@Newtonsoft.Json.JsonConvert.SerializeObject(Model.JsApiConfig)";
        jsApiConfigStr = jsApiConfigStr.replace(new RegExp("&quot;", "gm"), "\"");
        jsApiConfigStr = jsApiConfigStr.replace(new RegExp("\r\n", "gm"), "");
        jsApiConfigStr = jsApiConfigStr.replace(new RegExp("\n", "gm"), "");
        var jsApiConfig = eval('(' + jsApiConfigStr + ')');

        wx.config(jsApiConfig);

        loadData();
    });

    wx.ready(function () {
        wx.onMenuShareTimeline({
            title: '@Model.CampaignBundle.Campaign.ShareTimelineTitle', // 分享标题
            link: '@Request.Url.Scheme://@Request.Url.Host/Campaign/LuckyTicketShare/@Model.CampaignBundle.Campaign.Domain?campaignId=@Model.CampaignBundle.Campaign.Id&memberId=@ViewBag.Member.Id', // 分享链接
            imgUrl: '@Model.CampaignBundle.Campaign.ShareImageUrl', // 分享图标
            success: function () {
                shareSuccess("ShareTimeline");
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        });

        wx.onMenuShareAppMessage({
            title: '@Model.CampaignBundle.Campaign.ShareAppMessageTitle', // 分享标题
            desc: '@Model.CampaignBundle.Campaign.ShareAppMessageDescription', // 分享描述
            link: '@Request.Url.Scheme://@Request.Url.Host/Campaign/LuckyTicketShare/@Model.CampaignBundle.Campaign.Domain?campaignId=@Model.CampaignBundle.Campaign.Id&memberId=@ViewBag.Member.Id', // 分享链接
            imgUrl: '@Model.CampaignBundle.Campaign.ShareImageUrl', // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                shareSuccess("ShareAppMessage");
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        });
    });

    wx.error(function (res) {
        alert("error:" + res);
    });

    function shareSuccess(type) {
        var loadLayerIndex = layer.open({
            type: 2,
            shadeClose: false,
            content: '请稍候...'
        });

        $.ajax({
            url: "/Api/Campaign/" + type + "/@ViewBag.Domain.Id?campaignId=" + _campaignId,
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR) {
                // alert(data);

                layer.close(loadLayerIndex);
                if (data.Success) {
                    var resultObj = data.Data;

                    if (resultObj.Point == 0)
                        return;

                    var msg = "";
                    if (resultObj.Point > 0) {
                        msg += "获得积分：" + resultObj.Point;
                    }
                    if (msg != "") {
                        layerAlertBtn(msg);
                    }

                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                //alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function loadData(targetPage) {

        if (targetPage > _totalPage)
            return;

        var loadLayerIndex = layer.open({
            type: 2,
            shadeClose: false,
            content: '请稍候...'
        });

        var args = new Object();
        args.Page = targetPage || 1;
        args.PageSize = 10;
        args.CampaignId = _campaignId;

        $.ajax({
            url: "/Api/Campaign/GetLuckyTicketWinLogList/@ViewBag.Domain.Id",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR) {
                layer.close(loadLayerIndex);
                if (data.Success) {
                    var resultObj = data.Data;

                    _currentPage = resultObj.Page;
                    _totalPage = resultObj.TotalPage;
                    if (_currentPage >= _totalPage)
                    {
                        $("#divPagingContainer").html("没有更多了");
                    }

                    if(_currentPage==1)
                    {
                        document.getElementById('ticketNumberItemContainer').innerHTML = "";
                    }

                    var gettpl = document.getElementById('ticketNumberItemTemplate').innerHTML;
                    laytpl(gettpl).render(resultObj.ItemList, function (html) {
                        document.getElementById('ticketNumberItemContainer').innerHTML += html;
                    });

                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                //alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function showCampaignPage(){
        window.location.href= "/Campaign/LuckyTicket/@ViewBag.Domain.Id?campaignId=" + _campaignId
    }

    function showCampaignDescription() {
        var loadLayerIndex = layer.open({
            type: 2,
            shadeClose: false,
            content: '请稍候...'
        });

        $.ajax({
            url: "/Api/Campaign/GetCampaignDescription/@ViewBag.Domain.Id?id=" + _campaignId,
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR) {
                layer.close(loadLayerIndex);
                if (data.Success) {
                    var resultObj = data.Data;

                    var gettpl = document.getElementById('campaignDescription').innerHTML;

                    laytpl(gettpl).render(resultObj, function (html) {
                        var pageii = layer.open({
                            type: 1,
                            content: html,
                            shadeClose: false,
                            style: 'position:fixed; left:0.1rem; top:0.1rem;right:0.1rem; bottom:0.1rem; border:none;'
                        });
                    });

                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                //alert("Error: " + xmlHttpRequest.status);
            }
        });

    }

</script>

<script type="text/html" id="campaignDescription">
    <div style="position: fixed; top: 0.1rem; left: 0.1rem; right: 0.1rem; bottom: 0.45rem; overflow: auto;">
        {{ d }}
    </div>
    <div style="position: fixed; bottom: 0.1rem; left: 0.1rem; right: 0.1rem;">
        <div class="divRectangle_Gray" style="margin-top:0.1rem;" onclick="layer.closeAll()">
            关 闭
        </div>
    </div>
</script>

<script type="text/html" id="ticketNumberItemTemplate">
    {{# for(var i = 0, len = d.length; i < len; i=i+1){ }}
    {{# var headimg = fitHeadImage(d[i].Headimgurl,46) }}

    <div style="margin-bottom:0.25rem;">
        <div class="divLuckyTicketItem">
            {{ d[i].TicketNumber }}
        </div>
        <div style="margin-left:0.15rem;margin-right:0.15rem; color: #535353;margin-top:0.1rem;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td style="width:0.6rem;" valign="top">
                        <img src="{{headimg}}" style="width:0.5rem; height:0.5rem">
                    </td>
                    <td valign="top">
                        <div>
                            微信昵称：
                            {{# if(d[i].NickName != undefined && d[i].NickName != null){ }}
                            {{ d[i].NickName }}
                            {{# } }}
                        </div>
                        <div style="margin-top:0.07rem;">
                            中奖时间：{{ d[i].WinTime }}
                        </div>
                        <div style="margin-top:0.07rem;">
                            中奖说明：
                            {{# if(d[i].WinRemark != undefined && d[i].WinRemark != null){ }}
                            {{ d[i].WinRemark }}
                            {{# } }}
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    {{# } }}
</script>

<div id="divImageContainer">
    <img src="@Model.CampaignBundle.Campaign.ImageUrl" name="img" id="img" style="width: 100%;">
</div>

<div class="divContent">
    <div style="margin-top: 0.06rem" class="campaignName">
        @Model.CampaignBundle.Campaign.Name
    </div>
    <div style="margin-top: 0.06rem" class="campaignDescription">
        @Html.Raw(Model.CampaignBundle.Campaign.Introduction)
    </div>

    <div class="divRectangle" style="margin-top:0.15rem;padding-left:0.1rem;padding-right:0.1rem; padding-top:0.1rem;padding-bottom:0.1rem;
            font-size:0.13rem;">
        <div class="defaultColor">
            上次开奖时间：@Model.CampaignBundle.LuckyTicket.LastDrawTime
        </div>
    </div>

    <div style="margin-top:0.15rem; color: #535353;">
        中奖信息：
    </div>

    <div id="ticketNumberItemContainer" style="margin-top:0.1rem;font-size:0.13rem;">

    </div>

    <div id="divPagingContainer" class="divPagingContainer" style="margin-top:0.1rem; text-align:center" onclick="loadData(_currentPage+1)">
        查看更多
    </div>

   
</div>


<div id="divFooter">
    <table align="center" border="0" style="height:100%;width:100%">
        <tr>
            <td valign="middle" align="center" width="50%">
                <input name="" type="button" class="button" value="活动说明" style="width:90%" onclick="showCampaignDescription()">
            </td>
            <td valign="middle" align="center" width="50%">
                <input name="" type="button" class="button" value="返回活动页面" style="width:90%" onclick="showCampaignPage()">
            </td>
        </tr>
    </table>
</div>